package com.js.basehttp.utils;

// Created by JS on 2020/7/21.

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class RequestUtils {

    private static Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create();
    public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    /**
     * 组件requestBody
     * @param params
     * @return
     */
    public static RequestBody createRequestBody(Map<String, Object> params) {
        String jsonParams = gson.toJson(params);
        return RequestBody.create(JSON, jsonParams);
    }

    public static RequestBody createRequestBody(String param) {
        String jsonParams = gson.toJson(param);
        return RequestBody.create(JSON, jsonParams);
    }
}
